/****************************************************************************/
/* Copyright 2008 Jesse E. H-K                                              */
/*                                                                          */
/* This file is part of Icepac.                                             */
/*                                                                          */
/* Icepac is free software: you can redistribute it and/or modify           */
/* it under the terms of the GNU General Public License as published by     */
/* the Free Software Foundation, either version 3 of the License, or        */
/* (at your option) any later version.                                      */
/*                                                                          */
/* Icepac is distributed in the hope that it will be useful,                */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
/* GNU General Public License for more details.                             */
/*                                                                          */
/* You should have received a copy of the GNU General Public License        */
/* along with Icepac.  If not, see <http://www.gnu.org/licenses/>.          */
/****************************************************************************/

#ifndef ICEPAC_H_
#define ICEPAC_H_

#include "config.h"

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

/*
 * Constants defining important limits.
 */
#define LIBICEPAC_ERR_BUFF 512
#define LIBICEPAC_DIR_MAX 512
#define LIBICEPAC_BUFF_SIZE 256

/*
 * List the contents of a directory.
 * 
 * Parameters:
 * directory filename -- string
 * 
 * Given a directory name, return a table containing
 * its entries as strings. Hidden entries are not present in the table.
 * 
 * On error:
 * Returns nil and the error message.
 */
int icepac_listdir( lua_State *L );

/*
 * Iterate through the (non-hidden) entries of a directory.
 *
 * Parameters:
 * directory filename -- string
 *
 * Given a directory name, return an iterator through all the
 * entries.
 * Note that the filehandle is not closed until the looping stops
 * so in cases where there are many entries or recursion is involved,
 * it will likely be a better idea to use icepac_listdir instead.
 *
 * On error:
 * Returns nil and the error message.
 */
int icepac_iterdir( lua_State *L );

/*
 * Copy a file from src to dest.
 * 
 * Parameters:
 * source filename -- string
 * destination filename -- string
 * 
 * On error:
 * Returns nil and the error message. 
 */
int icepac_cpfile( lua_State *L );

/*
 * Creates the directory given by a string.
 * 
 * Parameters:
 * directory filename -- string
 * 
 * Given a directory name, creates a new directory with RWX priveledges
 * at the defined location.
 * 
 * Returns:
 * true when successful
 * 
 * On error:
 * Returns nil and the error message.
 */
int icepac_mkdir( lua_State *L );

/*
 * Determine if a file is a directory.
 * 
 * Parameters:
 * filename -- string
 * 
 * Check if the file described by a filename is
 * a directory.
 * 
 * Returns:
 * true when the file is a directory
 * false when the file is NOT a directory
 * 
 * On error:
 * Returns nil and the error message.
 */
int icepac_isdir( lua_State *L );

/*
 * Return the base name of a long path name.
 * 
 * Parameters:
 * pathname -- string
 * 
 * Behaves like the "basename" command.
 * For example, icepac.basename("/var/abs/local") => "local"
 * 
 * Returns:
 * The basename of the path.
 * 
 * On error:
 * TODO: add in proper error-handling for this function.
 */
int icepac_basename( lua_State *L );

#endif /*ICEPAC_H_*/
